/*
 * UIRoad.fx
 *
 * Created on Nov 3, 2009, 8:20:23 PM
 */

package dawnland02.ui;

import java.lang.*;
import java.util.*;

import javafx.scene.*;
import javafx.scene.layout.Container;
import javafx.scene.layout.Resizable;
import javafx.scene.layout.Stack;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.scene.transform.*;

import dawnland02.data.map.model.MatrixCell;
import dawnland02.data.map.model.MatrixDirection;
import dawnland02.service.GeneralService;

/**
 * @author Petru Obreja (obrejap@yahoo.com)
 */

public class UIRoad extends CustomNode{
    package var matrixCell : MatrixCell;
    package var centerX : Number;
    package var centerY : Number;
    package var radius : Number;
    package var roadLevel : Number;
    package var uiService : UIService;

    var neighboursRoadNodes : Map; //<MatrixDirection, Line>

    //override function getPrefWidth(height) {uiService.getUIHexagonPrefWidth()}
    //override function getPrefHeight(width) {uiService.getUIHexagonPrefHeight()}

    override function create(): Node {
        neighboursRoadNodes = new HashMap();
        var neighboursGroup : Container = Container {};
        //def neighbours = GeneralService.getMatrix().getNeighbours(matrixCell);
        for(matrixDirection in MatrixDirection.values()){
           if(matrixDirection==MatrixDirection.UP){
               continue;
           }
           var line = Line {
               startX: centerX  startY: centerY-centerX
               endX: centerX  endY: centerY-radius
               stroke: Color.RED;
               strokeWidth: bind (roadLevel + 1.0);
               visible: false
           }
           line.transforms = [Rotate {
                angle: uiService.getAngle(matrixDirection);
                pivotX: centerX;
                pivotY: centerY;
                }];
           if(matrixDirection==MatrixDirection.RIGHT){
           //if(matrixDirection==MatrixDirection.RIGHT or matrixDirection==MatrixDirection.LEFT){
               line.visible = true
           }

           neighboursRoadNodes.put(matrixDirection, line);
           insert line into neighboursGroup.content;           
        }
        def circle = Circle {
              centerX: centerX;
              centerY: centerY;
              radius: radius;
              stroke: Color.RED;
              strokeWidth: bind (roadLevel + 1.0);
              fill: Color.TRANSPARENT
          }
        Container{
            content: [circle, neighboursGroup]
        };
    }
}
